# quick script to notify of (ctcp|join) floods
my %c;

sub chanjoin {
   my($server, $channel, $nick, $address) = @_;
   return if $server->netsplit_find($nick, $address);
   flood_check($server,$channel);
}

sub chanctcp {
   my($server,$args,$nick,$address,$target) = @_;
   return if $args =~ /^ACTION /;
   return unless substr($target,0,1) eq '#';
   flood_check($server,$target);
}

sub flood_check {
   my($server,$channel) = @_;
   my $min = int(time/60);
   if($c{$channel}[0] != $min) {
      $c{$channel}[0] = $min;
      $c{$channel}[1] = 1;
   } else {
      $c{$channel}[1]++;
	  if($c{$channel}[1] >= 6) {
	     $c{$channel}[1] = 0;
		 $server->channel_find($channel)->print('Possible Flood', MSGLEVEL_HILIGHT);
	  }
   }
}

Irssi::signal_add('message join', \&chanjoin);
Irssi::signal_add('ctcp msg', \&chanctcp);
